﻿@inherits BasePlugin
@rendermode InteractiveServer

@namespace FluentCMS.Web.Plugins.Admin.ContentTypeManagement

<PluginBody Title="Content Type Fields" Visible="@(ContentType?.Fields != null)">
    <ActionsFragment>
        <ActionButtonBack @onclick="() => NavigateBack()" />
        <ActionButtonCreate @onclick=OnCreateFieldClick Label="New Field" />
    </ActionsFragment>
    <ChildContent>
        <DataTable Items="ContentType!.Fields!.ToList()">
            <DataTableItem Label="Name">
                @context.Name
            </DataTableItem>
            <DataTableItem Label="Label">
                @context.Label
            </DataTableItem>
            <DataTableItem Label="Type">
                <Stack>
                    <Icon Name="@FieldTypes.All[context.Type!]!.Icon"></Icon>
                    <Badge Color="Color.Primary">
                        @FieldTypes.All[context.Type!]?.Title
                    </Badge>
                </Stack>
            </DataTableItem>
            <DataTableItem Label="Required">
                <Indicator Color="Color.Success" Visible="@(context.Required)">Yes</Indicator>
                <Indicator Color="Color.Danger" Visible="@(!context.Required)">No</Indicator>
            </DataTableItem>
            <DataTableItem Label="Unique">
                <Indicator Color="Color.Success" Visible="@(context.Unique)">Yes</Indicator>
                <Indicator Color="Color.Danger" Visible="@(!context.Unique)">No</Indicator>
            </DataTableItem>
            <DataTableItem Label="Description">
                @context.Description
            </DataTableItem>
            <ActionButtons>
                <ActionButtonEdit @onclick="@(x=> OnEditFieldClick(context))" />
                <ActionButtonDelete @onclick="@(x=> OnDeleteFieldClick(context))" />
            </ActionButtons>
        </DataTable>
    </ChildContent>
</PluginBody>

<CascadingValue Value="ContentType">
    <CascadingValue Value="CurrentState">
        <ContentTypeFieldCreate OnComplete=LoadList Visible="CurrentState == FieldManagementState.Create" ContentTypeField="ContentTypeField" />
        <ContentTypeFieldUpdate OnComplete=LoadList Visible="CurrentState == FieldManagementState.Edit" ContentTypeField="ContentTypeField" />
        <ContentTypeFieldDelete OnComplete=LoadList Visible="CurrentState == FieldManagementState.Delete" ContentTypeField="ContentTypeField" />
    </CascadingValue>
</CascadingValue>
